﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Spiders
{
    class DomUtility
    {
        private static int[] ea = { 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2 };
        private static double[][] ma = new double[][] { new double[]{ 369, 101.08999633789062 }, new double[]{ 369, 101.08999633789062 }, new double[]{390,224.08999633789062}, new double[]{390,224.08999633789062}, new double[]{894,643}, new double[]{894,643}, new double[]{904,666}, new double[]{904,666}, new double[]{914,697}, 
                                      new double[]{419,4.089999675750732}, new double[]{422,11.09000015258789}, new double[]{424,5.089999675750732}, new double[]{923,706}, new double[]{921,693}, new double[]{921,693}, new double[]{16,21.09000015258789}, new double[]{474,747}, new double[]{513,683}, new double[]{513,683}, 
                                      new double[]{532,653}, new double[]{532,653}, new double[]{43,188.08999633789062}, new double[]{43,188.08999633789062}, new double[]{23,7.089999675750732}, new double[]{23,7.089999675750732}, new double[]{722,377}, new double[]{201,32.09000015258789}, new double[]{733,273}, 
                                      new double[]{734,245}, new double[]{736,217}, new double[]{739,186}, new double[]{742,158}, new double[]{754,93}, new double[]{287,27}, new double[]{767,52}, new double[]{772,42}, new double[]{780,36}, new double[]{793,27}, new double[]{804,43}, new double[]{334,12}, new double[]{789,188}, new double[]{777,247}, new double[]{233,11.09000015258789}, 
                                      new double[]{739,387}, new double[]{213,25.09000015258789}, new double[]{213,25.09000015258789}, new double[]{641,670}, new double[]{641,670}, new double[]{117,3.0899999141693115}, new double[]{1156,732}, new double[]{307,33.09000015258789}, new double[]{498,751}, new double[]{23,34.09000015258789}, 
                                      new double[]{35,15.089999198913574}, new double[]{547,703}, new double[]{559,689}, new double[]{559,689}, new double[]{589,645}, new double[]{589,645}, new double[]{94,224.08999633789062}, new double[]{94,224.08999633789062}, new double[]{99,178.08999633789062}, new double[]{99,178.08999633789062}, 
                                      new double[]{920,636}, new double[]{920,636}, new double[]{970,657}, new double[]{970,657}, new double[]{992,664}, new double[]{992,664}, new double[]{1004,665}, new double[]{1004,665}, new double[]{1006,665}, new double[]{1006,665}, new double[]{1030,669}, new double[]{1030,669}, new double[]{1039,667}, new double[]{1039,667}, new double[]{1035,686}, 
                                      new double[]{1035,686}, new double[]{1002,698} };

        /// <summary>
        /// 随机找出某个问题进行回答
        /// </summary>
        /// <param name="questions">问题列表</param>
        /// <returns>返回的问题</returns>
        public static Question FindRandomQuestion(IList<Question> questions)
        {
            if (questions.Count == 0)
            {
                return null;
            }
            Random ra = new Random((int)DateTime.Now.Ticks & 0x0000FFFF);
            int index = ra.Next(questions.Count);
            return questions[index];
        }

        /// <summary>
        /// 生成请求体的utdata数据
        /// </summary>
        /// <param name="initTime"></param>
        /// <returns></returns>
        public static string GenerateUtdata(long initTime)
        {
            int SH = Screen.PrimaryScreen.Bounds.Height;
            int SW = Screen.PrimaryScreen.Bounds.Width;
            string s = "1002,698\t2,3,2,3,2,3,2,3,2,2\t" + (DateTime.Now.GetTime() - initTime).ToString() + "\t" + SW + "," + SH;
            long j = DateTime.Now.GetTime();
            StringBuilder builder = new StringBuilder();
            var y = j % 100;
            for (int w = 0, v = s.Length; w < v; w++)
            {
                var A = s.CharCodeAt(w) ^ y;
                builder.Append(A).Append(',');
            }
            builder.Append(j).Append("1");
            return builder.ToString();
        }
    }
}
